﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace FalionForm
{
    /// <summary>
    /// Page1.xaml 的交互逻辑
    /// </summary>
    public partial class Page1 : Page
    {
        public Page1()
        {
            InitializeComponent();


           

        //   mu.DataSource = Enum.GetValues(typeof(AddresType_Melsec))
        //.Cast<Enum>()
        //.Select(value => new
        //{
        //    (Attribute.GetCustomAttribute(value.GetType().GetField(value.ToString()), typeof(DescriptionAttribute)) as DescriptionAttribute).Description,
        //    value
        //})
        //.OrderBy(item => item.value)
        //.ToList();


        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            this.Visibility = Visibility.Hidden;
        }
        List<Device> ds;
        private void button_Click(object sender, RoutedEventArgs e)
        {
            Array m = Enum.GetValues(typeof(AddresType_Siemens));
            var len = 50;
            ds = new List<Device>();
            for (int i = 0; i < len; i++)
            {
                var d1 = new Device()
                {
                    TP = m,
                    number = i,
                    address = 100,
                    cvalue = 100.1,
                    qvalue= 100.1,
                    addresType = AddresType_Siemens.DB,
                    dataType = DataType.Bool,
                    describe = "4,2,1",
                };
                ds.Add(d1);
            }
            this.gridList.ItemsSource = ds;
            //ObjectDataProvider op = new ObjectDataProvider();           
        }

    }

    public class Device
    {
        public Array TP { get; set; }
        public int number { get; set; }
        public int address { get; set; }
        public double cvalue { get; set; }
        public double qvalue { get; set; }
        public AddresType_Siemens addresType { get; set; }
        public DataType dataType { get; set; }
        public string describe { get; set; }

        public override string ToString()
        {
            return this.describe;
        }
    }
    public enum AddresType_Siemens    //西门子
    {
        [Description("DB")]
        DB = 1,
        [Description("M")]
        M = 2,
        [Description("I")]
        I =3,
        [Description("Q")]
        Q =4,
        [Description("T")]
        T =5,
        [Description("C")]
        C =6,
    }
    public enum AddresType_Melsec    //三菱
    {
        [Description("M")]
        M = 1,
        [Description("D")]
        D = 2,
        [Description("X")]
        X = 3,
        [Description("Y")]
        Y = 4,
    }
    public enum AddresType_Omron    //欧姆龙
    {
        [Description("D")]
        D = 1,
        [Description("C")]
        C = 2,
        [Description("W")]
        W = 3,
        [Description("H")]
        H = 4,
    }
    public enum DataType
    {
        [Description("bool")]
        Bool = 1,
        [Description("byte")]
        Byte = 2,
        [Description("short")]
        Short =3,
        [Description("ushort")]
        UShort =4,
        [Description("int")]
        Int = 5,
        [Description("uint")]
        UInt =6,
        [Description("long")]
        Long =7,
        [Description("ulong")]
        ULong =8,
        [Description("float")]
        Float = 9,
        [Description("double")]
        Double = 10,
        [Description("string")]
        String = 11,
    }
}
